package com.zhsource.system.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhsource.system.domain.Permission;
import com.zhsource.system.mapper.PermissionMapper;
import com.zhsource.system.query.PermissionQuery;
import com.zhsource.system.service.IPermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>@ClassName：PermissionServiceImpl
 * <p>@Date 2023/10/17  13:01
 *
 * @Author zzl
 **/
@Service
public class PermissionServiceImpl implements IPermissionService {

    @Autowired
    private PermissionMapper permissionMapper;

    @Override
    public List<Permission> list() {
        return permissionMapper.list();
    }

    @Override
    public Permission selectById(Long id) {
        return permissionMapper.selectById(id);
    }

    @Override
    public PageInfo<Permission> page(PermissionQuery permissionQuery) {
        // 1.下面这句代码表示开启分页，会将紧挨着这句代码的下一次数据库执行进行分页，切记一定要放在要分页的SQL语句前面执行
        PageHelper.startPage(permissionQuery.getCurrentPage(), permissionQuery.getPageSize());

        // 2.执行SQL语句带条件查询，SQL语句不需要进行分页
        List<Permission> page = permissionMapper.page(permissionQuery);
        // 3.将查询结果转换为PageInfo对象，PageInfo对象中有前端分页所需要的各种参数
        PageInfo<Permission> pageInfo = new PageInfo<>(page);
        // 4.响应总条数和分页信息
        return pageInfo;

    }

    @Override
    public void update(Permission permission) {
        permissionMapper.update(permission);
    }

    @Override
    public void insert(Permission permission) {

        permissionMapper.insert(permission);
    }

    @Override
    public void delete(Long id) {
        permissionMapper.delete(id);
    }

    @Override
    public void batchDel(List<Long> ids) {
        permissionMapper.batchDel(ids);
    }
}
